class Solution:
    def bestTeamScore(self, scores: list, ages: list) -> int:
        dp = [0 for _ in range(1000)]
        ans = 0
        for score, age in sorted(zip(scores, ages)):
            dp[age - 1] = score + max(dp[:age])
            ans = max(ans, dp[age - 1])
        return ans
